package cn.com.bluemoon.daps.api.sys.factory;

import cn.com.bluemoon.daps.api.sys.RemoteSystemInfoService;
import cn.com.bluemoon.daps.api.sys.RemoteSystemTagsService;
import cn.com.bluemoon.daps.common.constant.ServiceNameConstants;
import cn.com.bluemoon.daps.common.constant.ServiceNameConstants.DapsApiSystem;
import cn.com.bluemoon.daps.common.domain.ResultBean;
import cn.com.bluemoon.daps.common.enums.BmStatus;
import cn.com.bluemoon.daps.common.toolkit.FeignClientTools;
import cn.com.bluemoon.daps.system.dto.SystemInfoDto;
import cn.com.bluemoon.daps.system.entity.DapSystemInfo;
import cn.com.bluemoon.daps.system.entity.DapSystemTag;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Optional;

@Component
public class RemoteSystemTagsServiceFallbackFactory implements FallbackFactory<RemoteSystemTagsService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteSystemTagsServiceFallbackFactory.class);


    @Override
    public RemoteSystemTagsService create(Throwable throwable) {
        log.error("系统服务调用失败:{}", throwable.getMessage());
        return new RemoteSystemTagsService() {
            @Override
            public ResultBean<List<DapSystemTag>> getTags(String modelId, Integer status) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, DapsApiSystem.PROD_SERVICE, "获取系统标签列表失败");
            }

            @Override
            public ResultBean<List<DapSystemTag>> list() {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, DapsApiSystem.PROD_SERVICE, "获取系统标签列表失败");
            }

            @Override
            public ResultBean<Optional<DapSystemTag>> getByName(String name) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, DapsApiSystem.PROD_SERVICE, "获取系统标签列表失败");
            }
        };
    }
}
